package com.ruoyi.system.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HealthDailyInfoMapper;
import com.ruoyi.system.domain.HealthDailyInfo;
import com.ruoyi.system.service.IHealthDailyInfoService;
import com.ruoyi.common.core.text.Convert;

/**
 * 健康日报详情Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-02-21
 */
@Service
public class HealthDailyInfoServiceImpl implements IHealthDailyInfoService 
{
    @Autowired
    private HealthDailyInfoMapper healthDailyInfoMapper;

    /**
     * 查询健康日报详情
     * 
     * @param id 健康日报详情ID
     * @return 健康日报详情
     */
    @Override
    public HealthDailyInfo selectHealthDailyInfoById(String id)
    {
        return healthDailyInfoMapper.selectHealthDailyInfoById(id);
    }

    /**
     * 查询健康日报详情列表
     * 
     * @param healthDailyInfo 健康日报详情
     * @return 健康日报详情
     */
    @Override
    public List<HealthDailyInfo> selectHealthDailyInfoList(HealthDailyInfo healthDailyInfo)
    {
        return healthDailyInfoMapper.selectHealthDailyInfoList(healthDailyInfo);
    }

    /**
     * 新增健康日报详情
     * 
     * @param healthDailyInfo 健康日报详情
     * @return 结果
     */
    @Override
    public int insertHealthDailyInfo(HealthDailyInfo healthDailyInfo)
    {
    	String id = UUID.randomUUID().toString();
    	healthDailyInfo.setId(id);
    	Date date = new Date();
    	healthDailyInfo.setReportingDate(date);
    	healthDailyInfo.setReportingTime(date);
        return healthDailyInfoMapper.insertHealthDailyInfo(healthDailyInfo);
    }

    /**
     * 修改健康日报详情
     * 
     * @param healthDailyInfo 健康日报详情
     * @return 结果
     */
    @Override
    public int updateHealthDailyInfo(HealthDailyInfo healthDailyInfo)
    {
        return healthDailyInfoMapper.updateHealthDailyInfo(healthDailyInfo);
    }

    /**
     * 删除健康日报详情对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteHealthDailyInfoByIds(String ids)
    {
        return healthDailyInfoMapper.deleteHealthDailyInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除健康日报详情信息
     * 
     * @param id 健康日报详情ID
     * @return 结果
     */
    @Override
    public int deleteHealthDailyInfoById(String id)
    {
        return healthDailyInfoMapper.deleteHealthDailyInfoById(id);
    }

    /**
     * 根据手机号查询
     * 
     * @param userMobile 手机号
     * @return 结果
     */
	@Override
	public HealthDailyInfo queryByMobile(String userMobile, String today) {
		HealthDailyInfo healthDailyInfo = new HealthDailyInfo();
		healthDailyInfo.setUserMobile(userMobile);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//yyyy-mm-dd, 会出现时间不对, 因为小写的mm是代表: 秒
		Date todayDate = null;
		try {
			todayDate = sdf.parse(today);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		healthDailyInfo.setReportingDate(todayDate);
		return healthDailyInfoMapper.queryByMobile(healthDailyInfo);
	}

   
}
